<template>
    <div class="debris-list" v-loading="loading">
        <div class="input-box">
            <span class="input-title" style="margin-left:0px;">收益来源</span>
            <el-select @change="getList(1)" style="width:150px;" v-model="type">
                <el-option label="全部" :value="null"></el-option>
                <el-option label="队长补贴" :value="290"></el-option>
                <el-option label="大神接单收益" :value="300"></el-option>
            </el-select>
            <span class="input-title">注册时间</span>
            <el-date-picker
                @change="getList(1)"
                v-model="date"
                :clearable="true"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
            </el-date-picker>
            <el-button type="primary" class="btn" style="margin-left:20px" @click="getList(1)">查询</el-button>
        </div>
        <div class="table-box">
            <el-table :data="tableData" ref="table" border style="width: 100%">
                <el-table-column min-width="120" label="对局ID" prop="bid"></el-table-column>
                <el-table-column min-width="120" label="金额(趣金币)" prop="number"></el-table-column>
                <el-table-column min-width="120" label="收益来源" prop="type">
                    <template slot-scope="scope">
                        <div v-if="scope.row.type === 290">队长补贴</div>
                        <div v-if="scope.row.type === 300">大神接单收益</div>
                    </template>
                </el-table-column>
                <el-table-column width="170" label="收益时间">
                    <template slot-scope="scope">
                        <div>{{ tableFormatDate(scope.row.createTime) }}</div>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'

export default {
    name: 'userList',
    props: {
        tabIndex: ''
    },
    data () {
        return {
            pageNum: 1,
            pageSize: this._pageSize,
            keyWord: '',
            type: null,
            date: [],
            tableData: [],
            total: 0,
            loading: false
        }
    },
    created () {
        this.getList(1)
    },
    methods: {
        // 获取列表
        async getList (pageNum) {
            if (this.loading) return
            this.pageNum = pageNum
            this.loading = true
            let params = {
                pageNum,
                pageSize: this.pageSize,
                userId: this.$route.query.userId
            }
            params.type = this.type

            if (this.date && this.date.length) {
                params.fromDate = this.date[0] + ' 00:00:00'
                params.endDate = this.date[1] + ' 23:59:59'
            }

            let res = await this.$http.post('/team/startGameCoinDetail', params)
            if (res.code === '0') {
                this.tableData = res.data && res.data.list
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },
        goDetail (accountId, userId) {
            const { href } = this.$router.resolve({
                path: '/quDeal/accDetail',
                query: {
                    accountId, userId
                }
            })
            window.open(href, '_blank')
        },
        goOrderDetail (item) {
            let { id } = item
            const { href } = this.$router.resolve({
                path: '/team/legendary/userDetail',
                query: {
                    id
                }
            })
            window.open(href, '_blank')
        },
        // 查看用户详情
        goUserDetail (id) {
            const { href } = this.$router.resolve({
                path: '/dataReport/userInfo',
                query: {
                    id
                }
            })
            window.open(href, '_blank')
        },
        selectChange () {
            this.type = ''
            this.sort = ''
            this.$refs.table.clearSort()
            this.getList(1, 10)
        },
        // 页码切换
        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getList(1)
        },
        // 页容切换
        pageChange (val) {
            this.pageNum = val
            this.getList(this.pageNum)
        },
        tableFormatDate (time) {
            return formatDate(time, 'YYYY-MM-DD HH:MM:SS')
        }
    }
}
</script>

<style lang="scss" scoped>
    .debris-list {
        .input-box {
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin: 0 10px 0 20px;
            }
            .btn {
                margin-top: 10px;
                margin-left: 10px;
            }
        }

        .table-box {
            margin: 20px 0;
            .cover {
                width: 80px;
                height: 80px;
                > img {
                    width: 100%;
                    height: 100%;
                }
            }
            .user-icon {
                width: 20px;
                height: 20px;
                border-radius: 50%;
                margin-right: 5px;
                vertical-align: top;
            }
            .table-btn {
                cursor: pointer;
                color: #409EFF;
                font-size: 13px;
                font-weight: 500;
                &:hover {
                    text-decoration: underline;
                }
            }
        }
    }
    .tools {
        padding-right: 20px;
        display: flex;
        justify-content: flex-end;
    }
</style>
